package com.foreknow.protals.common.api;

import com.github.pagehelper.PageInfo;

import java.util.List;

/**
 * 分页通用工具类
 */
public class CommonPage<T> {
    private Integer pageNum; //页码
    private Integer pageSize;//每页显示的数据
    private Integer totalPage;//总页数
    private Long total;//总记录数
    private List<T> list;//每页查询的数据要保存到List集合中

    /**
     * 将集合转为分页信息
     * @param list 查询到的所有数据
     * @param <T>
     * @return
     */
    public static <T> CommonPage<T> restPage(List<T> list) {
        CommonPage<T> rest = new CommonPage<>();
        PageInfo<T> pageInfo = new PageInfo<>(list);
        rest.setTotalPage(pageInfo.getPages());
        rest.setPageNum(pageInfo.getPageNum());
        rest.setPageSize(pageInfo.getPageSize());
        rest.setTotal(pageInfo.getTotal());
        rest.setList(pageInfo.getList());
        return rest;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Long getTotal() {
        return total;
    }

    public void setTotal(Long total) {
        this.total = total;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
}
